import React from 'react';
import { observer, inject } from 'mobx-react';
import MainLayout from '../layout/MainLayout';
import LogList from '../../asyncComps/LogList';
import * as _ from '../../util/public/common';
import * as FormUtil from '../../util/formUtil';
import { controlAsyncLoad } from '../../util/asyncLoad';
import * as GlobalUtil from "../../util/public/globalUtil";

@inject('globalStore', 'layoutStore')
@observer
export default class ReqPrint extends React.Component{
    constructor(){
        super();
    }
    componentDidMount() {
        const { globalStore } = this.props;
        jQuery("body").css("overflow", globalStore.urlParams.isBatchPrint === "true" ? "hidden" : "auto");
        jQuery("#container").css("padding", "6px 10px");
        jQuery("#container").css("height","auto");
        controlAsyncLoad();
        GlobalUtil.loadCaculateResource();
        const { browserVersion } = globalStore;
        if(browserVersion && browserVersion.indexOf("IE") > -1)
            jQuery(".wf-req-print").append('<object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0"></object>');
    }
    componentDidUpdate(preProps) {
        controlAsyncLoad();
    }
    componentWillUnmount() {
        const { globalStore } = this.props;
        globalStore.resetStore();
    }
    render(){
        const { globalStore,layoutStore } = this.props;
        const { JSComplete,commonParam,rightMenu,variableMap,controlVariableMap } = globalStore;
        const { forward } = rightMenu;
        const { dataJson } = layoutStore;
        const hasLoad = !_.isEmpty(commonParam) && !_.isEmpty(dataJson);
        const printLogList = hasLoad ? FormUtil.judgePrintLogList() : false;
        return (
            <div className="wf-req-print">
                <div className='wf-req-form' style={{margin:"0 auto", marginBottom:'20px'}}>
                { 
                    hasLoad && <MainLayout ecId={`${this && this.props && this.props.ecId || ''}_MainLayout@fu3w5c`} symbol="main" />
                }
                </div>
                <div className='wf-req-loglist'>
                {
                    printLogList && <LogList ecId={`${this && this.props && this.props.ecId || ''}_LogList@i3gvqp`} commonParam={commonParam} forward={forward} controlVariableMap={controlVariableMap} isRelaodLogList={variableMap.get('isRelaodLogList')} reloadLogListParams={variableMap.get('reloadLogListParams')}/>
                }
                </div>
            </div>
        )
    }
}